//
//  SettingsViewController.m
//  Molian
//
//  Created by 胡津 on 15/4/1.
//  Copyright (c) 2015年 xiaocan. All rights reserved.
//

#import "SettingsViewController.h"
#import "FeedbackViewController.h"
#import "MLinfoViewController.h"
#import "BlacklistViewController.h"
#import "LoginViewController.h"
#import "SetMessageViewController.h"
#import "LoveExperienceViewController.h"
#import "ApplicationRecommendViewController.h"
#import "BindingMobilePhoneViewController.h"
#import "PhoneViewController.h"
#import "WEBViewController.h"

@interface SettingsViewController ()<UITableViewDelegate,UITableViewDataSource,UMSocialUIDelegate,BindingMobilePhoneViewControllerDelegate>
//视图列表
@property (nonatomic, strong)UITableView *tableView;

@end

@implementation SettingsViewController
{
    NSArray *titleArr;
    NSArray *iconArr;
    NSString *clearCacheName;
    NSInteger imagerow;
}

- (void)buttonAction:(id)buttonAction
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = APPCOLORBACKGROUNDCOLOR(1);
    self.title = @"更多";
    clearCacheName = @"";
    [self GetSize];
    
    titleArr = @[@[@"消息设置",@"意见反馈"],@[@"黑名单",clearCacheName],@[@"关于我们"],@[@"退出账号"]];
    iconArr=@[@[@"setting_icon_0",@"setting_icon_3"],@[@"setting_icon_4",@"setting_icon_6"],@[@"mine_more_about-us_icon"],@[@"setting_icon_9"]];
    
//    titleArr = @[@[@"成为专属恋人 HOT",@"绑定手机号"],@[@"消息设置",@"邀请好友",@"给我评分",@"意见反馈"],@[@"黑名单",clearCacheName],@[@"关于我们"],@[@"退出账号"]];
//    iconArr=@[@[@"mine_more_lover_icon",@"icon_binding_phone_number"],@[@"setting_icon_0",@"setting_icon_1",@"setting_icon_2",@"setting_icon_3"],@[@"setting_icon_4",@"setting_icon_6"],@[@"mine_more_about-us_icon"],@[@"setting_icon_9"]];
    //    if ([Utils cheackConfigurationScreen]) {
    //
    //        if ([MLUser currentUser].type == MLUserType_NORMAL) {
    //            //普通用户可以成为专属恋人
    //            titleArr = @[@[@"绑定手机号"],@[@"消息设置",@"邀请好友",@"给我评分",@"意见反馈"],@[@"黑名单",clearCacheName],@[@"关于我们"],@[@"退出账号"]];
    //            iconArr =@[@[@"icon_binding_phone_number"],@[@"setting_icon_0",@"setting_icon_1",@"setting_icon_2",@"setting_icon_3"],@[@"setting_icon_4",@"setting_icon_6"],@[@"mine_more_about-us_icon"],@[@"setting_icon_9"]];
    //
    //        }else if ([MLUser currentUser].type == MLUserType_POCKET){
    //            //专属恋人可以申请上了编辑推荐
    //            titleArr = @[@[@"成为梦想恋人",@"无独团须知",@"绑定手机号"],@[@"消息设置",@"邀请好友",@"给我评分",@"意见反馈"],@[@"黑名单",clearCacheName],@[@"关于我们"],@[@"退出账号"]];
    //            iconArr =@[@[@"icon_apply_for_recommend",@"setting_icon_02",@"icon_binding_phone_number"],@[@"setting_icon_0",@"setting_icon_1",@"setting_icon_2",@"setting_icon_3"],@[@"setting_icon_4",@"setting_icon_6"],@[@"mine_more_about-us_icon"],@[@"setting_icon_9"]];
    //        }else{
    //            titleArr = @[@[@"绑定手机号",@"无独团须知"],@[@"消息设置",@"邀请好友",@"给我评分",@"意见反馈"],@[@"黑名单",clearCacheName],@[@"关于我们"],@[@"退出账号"]];
    //            iconArr =@[@[@"icon_binding_phone_number",@"setting_icon_02"],@[@"setting_icon_0",@"setting_icon_1",@"setting_icon_2",@"setting_icon_3"],@[@"setting_icon_4",@"setting_icon_6"],@[@"mine_more_about-us_icon"],@[@"setting_icon_9"]];
    //        }
    //    }else{
    //        if ([MLUser currentUser].type == MLUserType_NORMAL) {
    //            //普通用户可以成为专属恋人
    //            titleArr = @[@[@"成为专属恋人 HOT",@"绑定手机号"],@[@"消息设置",@"邀请好友",@"给我评分",@"意见反馈"],@[@"黑名单",clearCacheName],@[@"关于我们"],@[@"退出账号"]];
    //            iconArr =@[@[@"mine_more_lover_icon",@"icon_binding_phone_number"],@[@"setting_icon_0",@"setting_icon_1",@"setting_icon_2",@"setting_icon_3"],@[@"setting_icon_4",@"setting_icon_6"],@[@"mine_more_about-us_icon"],@[@"setting_icon_9"]];
    //
    //        }else if ([MLUser currentUser].type == MLUserType_POCKET){
    //            //专属恋人可以申请上了编辑推荐
    //            titleArr = @[@[@"成为梦想恋人",@"无独团须知",@"绑定手机号"],@[@"消息设置",@"邀请好友",@"给我评分",@"意见反馈"],@[@"黑名单",clearCacheName],@[@"关于我们"],@[@"退出账号"]];
    //            iconArr =@[@[@"icon_apply_for_recommend",@"setting_icon_02",@"icon_binding_phone_number"],@[@"setting_icon_0",@"setting_icon_1",@"setting_icon_2",@"setting_icon_3"],@[@"setting_icon_4",@"setting_icon_6"],@[@"mine_more_about-us_icon"],@[@"setting_icon_9"]];
    //        }else{
    //            titleArr = @[@[@"绑定手机号",@"无独团须知"],@[@"消息设置",@"邀请好友",@"给我评分",@"意见反馈"],@[@"黑名单",clearCacheName],@[@"关于我们"],@[@"退出账号"]];
    //            iconArr =@[@[@"icon_binding_phone_number",@"setting_icon_02"],@[@"setting_icon_0",@"setting_icon_1",@"setting_icon_2",@"setting_icon_3"],@[@"setting_icon_4",@"setting_icon_6"],@[@"mine_more_about-us_icon"],@[@"setting_icon_9"]];
    //        }
    //    }
    
    
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, DeviceWidth, DeviceHeight)style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = RGBA(240, 237, 244, 1);
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollsToTop = YES;
    self.tableView.separatorColor = RGBA(225, 225, 225, 1);//分隔条颜色
    self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 20, 0);//偏移量
    self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 51, 0);//滚动条偏移量
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
    self.tableView.tableFooterView = [[UIView alloc] init];//不显示空的cell
    [self.view addSubview:self.tableView];
    
    
    //退出按钮
    //    BFPaperButton *OUT = [[BFPaperButton alloc]initWithFrame:CGRectMake(20, 50 * titleArr.count*2+130 +50, DeviceWidth-40, 45 )];
    //    [OUT setTitle:@"退出账号" forState:UIControlStateNormal];
    //    [OUT setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //    OUT.layer.masksToBounds = YES;//开启圆角
    //    [OUT setBackgroundImage:[UIImage imageWithColor:[UIColor paperColorRedA200]] forState:UIControlStateNormal];
    //    [OUT.layer setCornerRadius:CGRectGetHeight([OUT bounds]) / 2];
    //    OUT.titleLabel.font = [UIFont fontWithName:FontName size:14];
    ////    [OUT addTarget:self action:@selector(OUT) forControlEvents:UIControlEventTouchUpInside];
    //    [self.tableView addSubview:OUT];
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static  NSString *CellIdentifier = @"SettingsCell" ;
    //自定义cell类
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if  (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
        imagerow++;
        
    }
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头，距离右边有十几像素；
    
    NSString *str = [[titleArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    
    if ([str isEqualToString:@"成为专属恋人 HOT"]) {
        cell.textLabel.textColor = RGBA(51, 51, 51, 1);
        cell.textLabel.font = [UIFont fontWithName:FontName size:16];
        NSString *title =  [[titleArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
        NSMutableAttributedString *mString = [[NSMutableAttributedString alloc] initWithString:title];
        [mString addAttribute:NSForegroundColorAttributeName value:APPCOLOR(1) range:NSMakeRange(title.length-3,3)];
        [mString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:12] range:NSMakeRange(title.length-3,3)];
        cell.textLabel.attributedText = mString;
        
    }else{
        cell.textLabel.text = [[titleArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
        cell.textLabel.textColor = RGBA(51, 51, 51, 1);
        cell.textLabel.font = [UIFont fontWithName:FontName size:16];
        
    }
    
    //    if (indexPath.section==0&&indexPath.row == 0&&[MLUser currentUser].type ==MLUserType_NORMAL) {
    //
    //        if ([Utils cheackConfigurationScreen]) {
    //            cell.textLabel.text = [[titleArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    //            cell.textLabel.textColor = RGBA(51, 51, 51, 1);
    //            cell.textLabel.font = [UIFont fontWithName:FontName size:16];
    //        }else{
    //            cell.textLabel.textColor = RGBA(51, 51, 51, 1);
    //            cell.textLabel.font = [UIFont fontWithName:FontName size:16];
    //            NSString *title =  [[titleArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    //            NSMutableAttributedString *mString = [[NSMutableAttributedString alloc] initWithString:title];
    //            [mString addAttribute:NSForegroundColorAttributeName value:APPCOLOR(1) range:NSMakeRange(title.length-3,3)];
    //            [mString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:12] range:NSMakeRange(title.length-3,3)];
    //            cell.textLabel.attributedText = mString;
    //        }
    //
    //
    //    }else{
    //        cell.textLabel.text = [[titleArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    //        cell.textLabel.textColor = RGBA(51, 51, 51, 1);
    //        cell.textLabel.font = [UIFont fontWithName:FontName size:16];
    //    }
    
    cell.imageView.image = [UIImage imageNamed:[[iconArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]];
    
    if (indexPath.section == 1) {
        if (indexPath.row == 1) {
            cell.textLabel.text = clearCacheName;
        }
    }
    
    cell.backgroundColor = [UIColor whiteColor];
    return  cell;
}
- (void)bindingPhoneSucceeded
{
    [self.navigationController pushViewController:[[PhoneViewController alloc]init] animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSString *str = [[titleArr objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    
    if ([str isEqualToString:@"成为梦想恋人"]) {
        //上编辑推荐
        ApplicationRecommendViewController *loveExperience = [[ApplicationRecommendViewController alloc] init];
        [self.navigationController pushViewController:loveExperience animated:YES];
        
    }else if ([str isEqualToString:@"成为专属恋人 HOT"]) {
        //成为专属恋人
        LoveExperienceViewController *loveExperience = [[LoveExperienceViewController alloc] init];
        [self.navigationController pushViewController:loveExperience animated:YES];
        
    }else if ([str isEqualToString:@"无独团须知"]) {
        WEBViewController *web = [[WEBViewController alloc]init];
        web.WEBURL = @"http://www.wudutuan.com/howtobe";
        [Utils pushTabbarHidden:web Selfvc:self];
        [AVAnalytics event:@"无独团须知"]; // 通知服务器一个点击事件。
        
    }else if ([str isEqualToString:@"绑定手机号"]) {
        if (![MLUser currentUser].notifyPhoneNum) {
            
            BindingMobilePhoneViewController *bindingMPVC = [[BindingMobilePhoneViewController alloc]init];
            bindingMPVC.delegate = self;
            [self.navigationController pushViewController:bindingMPVC animated:YES];
        }else{
            [self.navigationController pushViewController:[[PhoneViewController alloc]init] animated:YES];
        }
        
    }else if ([str isEqualToString:@"消息设置"]) {
        // //消息设置
        SetMessageViewController *setMVC = [[SetMessageViewController alloc] init];
        [self.navigationController pushViewController:setMVC animated:YES];
        
        
    }else if ([str isEqualToString:@"邀请好友"]) {
        //发福利
        [self Actionshare];
        
    }else if ([str isEqualToString:@"给我评分"]) {
        //跪求好评
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=957185702&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8"]];
        
    }else if ([str isEqualToString:@"意见反馈"]) {
        //意见反馈
        [self.navigationController pushViewController:[[FeedbackViewController alloc]init] animated:YES];
    }else if ([str isEqualToString:@"黑名单"]) {
        //黑名单
        [self.navigationController pushViewController:[[BlacklistViewController alloc]init] animated:YES];
        
    }else if ([str isEqualToString:@"关于我们"]) {
        [self.navigationController pushViewController:[[MLinfoViewController alloc]init] animated:YES];
        
    }else if ([str isEqualToString:@"退出账号"]) {
        HUD*hud = [[HUD alloc]init];
        [hud HUDImage:nil Title:@"退出" Content:@"确定要退出当前账号?" CANCEL:@"取消" Confirm:@"确定"];
        hud.Confirm  = ^{
            
            [HUD setOnViewWithTitle:@"退出中" animated:YES];
            [[EaseMob sharedInstance].chatManager asyncLogoffWithUnbindDeviceToken:YES completion:^(NSDictionary *info, EMError *error) {
                [HUD hideFromViewAnimated:YES];
                if (error == nil) {
                    
                    self.tabBarController.selectedIndex = 0;
                  //  [self.navigationController popToRootViewControllerAnimated:YES];
                    //退出登录
                    [Utils quitLogin];
                    
                    self.hidesBottomBarWhenPushed = NO;
                    [self.navigationController popToRootViewControllerAnimated:YES];
                    self.tabBarController.selectedIndex = 0;
                }else{
                    
                    [[EaseMob sharedInstance].chatManager asyncLogoffWithUnbindDeviceToken:YES completion:^(NSDictionary *info, EMError *error) {
                        [HUD hideFromViewAnimated:YES];
                        if (error == nil) {
                            self.tabBarController.selectedIndex = 0;
                            [self.navigationController popToRootViewControllerAnimated:YES];
                            //退出登录
                            [Utils quitLogin];
                            
                            self.hidesBottomBarWhenPushed = NO;
                            [self.navigationController popToRootViewControllerAnimated:YES];
                            self.tabBarController.selectedIndex = 0;
                        }else{
                            [HUD Prompt:@"退出失败"];
                        }
                    } onQueue:nil];
                }
                
            } onQueue:nil];
        };
        hud.Cancel = ^{
            NSLog(@"取消");
        };
        [self.view addSubview:hud];
        
    }else {
        if(indexPath.section == 1&& indexPath.row == 1){
            //清理缓存
            if ([self GetSize] == 0) {
                [HUD Prompt:@"没有需要清理的缓存"];
                return;
            }
            NSString *str = [self GetSize] >= 1 ? [NSString stringWithFormat:@"缓存大小为(%.2fM),确定要清理缓存吗?",[self GetSize]] : [NSString stringWithFormat:@"缓存大小为(%.2fK),确定要清理缓存吗?",[self GetSize] < 1 ? 0:[self GetSize] * 1024];
            
            HUD*hud = [[HUD alloc]init];
            [hud HUDImage:nil Title:@"清理缓存" Content:str CANCEL:@"取消" Confirm:@"确定"];
            hud.Confirm  = ^{
                [HUD setOnViewWithTitle:@"清除缓存中" animated:YES];
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                    NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) firstObject];
                    NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
                    for (NSString *p in files) {
                        NSError *error;
                        NSString *path = [cachPath stringByAppendingPathComponent:p];
                        if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
                            [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
                        }
                    }
                    [self performSelectorOnMainThread:@selector(clearCacheSuccess) withObject:nil waitUntilDone:YES];
                });
            };
            hud.Cancel = ^{
                NSLog(@"取消");
            };
            [self.view addSubview:hud];
            
        }
        
    }
    
    
    
    
    
    
    
    
    //    if (indexPath.section == 0) {
    //        if (indexPath.row == 0) {
    //            if ([MLUser currentUser].type == MLUserType_NORMAL) {
    //
    //                if ([Utils cheackConfigurationScreen]) {
    //                    if (![MLUser currentUser].notifyPhoneNum) {
    //
    //                        BindingMobilePhoneViewController *bindingMPVC = [[BindingMobilePhoneViewController alloc]init];
    //                        bindingMPVC.delegate = self;
    //                        [self.navigationController pushViewController:bindingMPVC animated:YES];
    //                    }else{
    //                        [self.navigationController pushViewController:[[PhoneViewController alloc]init] animated:YES];
    //                    }
    //                }else{
    //                    //成为专属恋人
    //                    LoveExperienceViewController *loveExperience = [[LoveExperienceViewController alloc] init];
    //                    [self.navigationController pushViewController:loveExperience animated:YES];
    //                }
    //
    //
    //            }else if ([MLUser currentUser].type == MLUserType_POCKET){
    //                //上编辑推荐
    //                ApplicationRecommendViewController *loveExperience = [[ApplicationRecommendViewController alloc] init];
    //                [self.navigationController pushViewController:loveExperience animated:YES];
    //            }else{
    //                //绑定手机号
    //                if (![MLUser currentUser].notifyPhoneNum) {
    //
    //                    BindingMobilePhoneViewController *bindingMPVC = [[BindingMobilePhoneViewController alloc]init];
    //                    bindingMPVC.delegate = self;
    //                    [self.navigationController pushViewController:bindingMPVC animated:YES];
    //                }else{
    //                    [self.navigationController pushViewController:[[PhoneViewController alloc]init] animated:YES];
    //                }
    //            }
    //        }else if (indexPath.row == 1){
    //            if ([MLUser currentUser].type == MLUserType_NORMAL) {
    //                if (![MLUser currentUser].notifyPhoneNum) {
    //
    //                    BindingMobilePhoneViewController *bindingMPVC = [[BindingMobilePhoneViewController alloc]init];
    //                    bindingMPVC.delegate = self;
    //                    [self.navigationController pushViewController:bindingMPVC animated:YES];
    //                }else{
    //                    [self.navigationController pushViewController:[[PhoneViewController alloc]init] animated:YES];
    //                }
    //            }else{
    //                WEBViewController *web = [[WEBViewController alloc]init];
    //                web.WEBURL = @"http://www.wudutuan.com/howtobe";
    //                [Utils pushTabbarHidden:web Selfvc:self];
    //                [AVAnalytics event:@"无独团须知"]; // 通知服务器一个点击事件。
    //            }
    //
    //
    //        }else{
    //
    //            if (![MLUser currentUser].notifyPhoneNum) {
    //
    //                BindingMobilePhoneViewController *bindingMPVC = [[BindingMobilePhoneViewController alloc]init];
    //                bindingMPVC.delegate = self;
    //                [self.navigationController pushViewController:bindingMPVC animated:YES];
    //            }else{
    //                [self.navigationController pushViewController:[[PhoneViewController alloc]init] animated:YES];
    //            }
    //        }
    //    }
    //    if (indexPath.section == 1) {
    //        NSInteger i = indexPath.row;
    //        //        if ([MLUser currentUser].type == MLUserType_NORMAL || [MLUser currentUser].type == MLUserType_POCKET) {
    //        //            i = indexPath.row;
    //        //        }else{
    //        //            i = indexPath.row+1;
    //        //        }
    //        switch (i) {
    //            case 0:
    //            {
    //                // //消息设置
    //                SetMessageViewController *setMVC = [[SetMessageViewController alloc] init];
    //                [self.navigationController pushViewController:setMVC animated:YES];
    //            }
    //                break;
    //            case 1:
    //            {
    //                //发福利
    //                [self Actionshare];
    //            }
    //                break;
    //            case 2:
    //            {
    //                //跪求好评
    //                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=957185702&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8"]];
    //            }
    //                break;
    //            case 3:
    //            {
    //                //意见反馈
    //                [self.navigationController pushViewController:[[FeedbackViewController alloc]init] animated:YES];
    //            }
    //                break;
    //            default:
    //                break;
    //        }
    //    }else if (indexPath.section == 2){
    //        switch (indexPath.row) {
    //            case 0:
    //            {
    //                //黑名单
    //                [self.navigationController pushViewController:[[BlacklistViewController alloc]init] animated:YES];
    //            }
    //                break;
    //                //            case 1:
    //                //            {
    //                //                //检测更新
    //                //                [self onCheckVersion];
    //                //            }
    //                //                break;
    //            case 1:
    //            {
    //                if ([self GetSize] == 0) {
    //                    [HUD Prompt:@"没有需要清理的缓存"];
    //                    return;
    //                }
    //                NSString *str = [self GetSize] >= 1 ? [NSString stringWithFormat:@"缓存大小为(%.2fM),确定要清理缓存吗?",[self GetSize]] : [NSString stringWithFormat:@"缓存大小为(%.2fK),确定要清理缓存吗?",[self GetSize] < 1 ? 0:[self GetSize] * 1024];
    //
    //                HUD*hud = [[HUD alloc]init];
    //                [hud HUDImage:nil Title:@"清理缓存" Content:str CANCEL:@"取消" Confirm:@"确定"];
    //                hud.Confirm  = ^{
    //                    [HUD setOnViewWithTitle:@"清除缓存中" animated:YES];
    //                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    //                        NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) firstObject];
    //                        NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
    //                        for (NSString *p in files) {
    //                            NSError *error;
    //                            NSString *path = [cachPath stringByAppendingPathComponent:p];
    //                            if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
    //                                [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
    //                            }
    //                        }
    //                        [self performSelectorOnMainThread:@selector(clearCacheSuccess) withObject:nil waitUntilDone:YES];
    //                    });
    //                };
    //                hud.Cancel = ^{
    //                    NSLog(@"取消");
    //                };
    //                [self.view addSubview:hud];
    //
    //            }
    //                break;
    //            default:
    //                break;
    //        }
    //    }else if (indexPath.section == 3){
    //        [self.navigationController pushViewController:[[MLinfoViewController alloc]init] animated:YES];
    //    }else if (indexPath.section == 4){
    //        NSLog(@"退出");
    //
    //        HUD*hud = [[HUD alloc]init];
    //        [hud HUDImage:nil Title:@"退出" Content:@"确定要退出当前账号?" CANCEL:@"取消" Confirm:@"确定"];
    //        hud.Confirm  = ^{
    //
    //            [HUD setOnViewWithTitle:@"退出中" animated:YES];
    //            [[EaseMob sharedInstance].chatManager asyncLogoffWithUnbindDeviceToken:YES completion:^(NSDictionary *info, EMError *error) {
    //                 [HUD hideFromViewAnimated:YES];
    //                if (error == nil) {
    //
    //                    self.tabBarController.selectedIndex = 1;
    //                    [self.navigationController popToRootViewControllerAnimated:YES];
    //                    //退出登录
    //                    [Utils quitLogin];
    //
    //                    self.hidesBottomBarWhenPushed = NO;
    //                    [self.navigationController popToRootViewControllerAnimated:YES];
    //                    self.tabBarController.selectedIndex = 1;
    //                }else{
    //
    //                    [[EaseMob sharedInstance].chatManager asyncLogoffWithUnbindDeviceToken:YES completion:^(NSDictionary *info, EMError *error) {
    //                        [HUD hideFromViewAnimated:YES];
    //                        if (error == nil) {
    //                            self.tabBarController.selectedIndex = 1;
    //                            [self.navigationController popToRootViewControllerAnimated:YES];
    //                            //退出登录
    //                            [Utils quitLogin];
    //
    //                            self.hidesBottomBarWhenPushed = NO;
    //                            [self.navigationController popToRootViewControllerAnimated:YES];
    //                            self.tabBarController.selectedIndex = 1;
    //                        }else{
    //                            [HUD Prompt:@"退出失败"];
    //                        }
    //                    } onQueue:nil];
    //                }
    //
    //            } onQueue:nil];
    //        };
    //        hud.Cancel = ^{
    //            NSLog(@"取消");
    //        };
    //        [self.view addSubview:hud];
    //
    //    }
    
}

-(float)GetSize
{
    NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) firstObject];
    float totalSize = 0;
    NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:cachPath];
    for (NSString *fileName in fileEnumerator)
    {
        NSString *filePath = [cachPath stringByAppendingPathComponent:fileName];
        NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
        unsigned long long length = [attrs fileSize];
        totalSize += length / 1024.0 / 1024.0;
    }
    clearCacheName = totalSize >= 1 ? [NSString stringWithFormat:@"清理缓存 (%.2fM)",totalSize] : [NSString stringWithFormat:@"清理缓存 (%.2fK)",totalSize < 1 ? 0:totalSize * 1024];
    
    return totalSize;
}

-(void)clearCacheSuccess
{
    [self GetSize];
    [HUD hideFromViewAnimated:YES];
    [self.tableView reloadData];
}

//分享
-(void)Actionshare
{
    //如果需要分享回调,请将delegate对象设置self,并实现下面的回调方法
    [UMSocialSnsService handleOpenURL:[NSURL URLWithString:@"http://www.wudutuan.com/wap"]];
    
    [UMSocialData defaultData].extConfig.wechatSessionData.url = @"http://www.wudutuan.com/wap";
    [UMSocialData defaultData].extConfig.qqData.url = @"http://www.wudutuan.com/wap";
    
    
    
    //如果需要分享回调,请将delegate对象设置self,并实现下面的回调方法
    [UMSocialData defaultData].extConfig.title = @"无独团——陌生人虚拟恋爱社交APP";
    
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:UM_KEY
                                      shareText:@"无独团是一款走心、自由的陌生人虚拟恋爱社交APP。在无独团可以免费和陌生人虚拟恋爱,亲爱的快来试试吧"
                                     shareImage:[UIImage imageNamed:@"icon"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToWechatSession,UMShareToWechatTimeline,UMShareToQQ,UMShareToQzone,UMShareToDouban,UMShareToRenren,UMShareToSms,nil]
                                       delegate:self];
}

//下面得到分享完成的回调
-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    NSLog(@"didFinishGetUMSocialDataInViewController with response is %@",response);
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的微博平台名
        [HUD Prompt:@"成功!"];
    }else{
        //        [HUD Prompt:@"失败" Content:@"分享失败" Timer:2];
        
    }
}

//用户分享或者关闭分享页面的回调方法
-(void)didCloseShakeView
{
    //    [HUD Prompt:@"我们做的不够好?" Content:@"是吗?" Timer:2];
}

-(void)onCheckVersion
{
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    //CFShow((__bridge CFTypeRef)(infoDic));
    NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
    
    NSString *URL = @"http://itunes.apple.com/lookup?id=957185702";
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:URL]];
    [request setHTTPMethod:@"POST"];
    NSHTTPURLResponse *urlResponse = nil;
    NSError *error = nil;
    NSData *recervedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
    id jsonObject = [NSJSONSerialization JSONObjectWithData:recervedData options:NSJSONReadingAllowFragments error:nil];
    
    NSArray *infoArray = [jsonObject objectForKey:@"results"];
    if ([infoArray count]) {
        NSDictionary *releaseInfo = [infoArray firstObject];
        NSString *lastVersion = [releaseInfo objectForKey:@"version"];
        if (![lastVersion isEqualToString:currentVersion]) {
            HUD*hud = [[HUD alloc]init];
            [hud HUDImage:nil Title:@"版本更新" Content:@"已发现新的版本,确定要进行更新?" CANCEL:@"取消" Confirm:@"确定"];
            hud.Confirm  = ^{
                NSURL *url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/us/app/mo-lian/id957185702?l=zh&ls=1&mt=8"];
                [[UIApplication sharedApplication]openURL:url];
            };
            hud.Cancel = ^{
                NSLog(@"取消");
            };
            [self.view addSubview:hud];
        }
        else
        {
            [HUD Prompt:@"此版本为最新版本"];
        }
    }
}

//section个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [titleArr count];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[titleArr objectAtIndex:section] count];//Cell个数
}

//设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;//每个cell的头部间距
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
{
    return 10;//每个cell的底部间距
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    if ([self isViewLoaded]&&!self.view.window) {
        self.view = nil;
    }
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
